'''
元字符：正则表达式种居于一些特殊含义的字符，比如重复N次前面的字符……
'''
#任意匹配元字符
import re
string = 'abcdfphp345pythony_py'
pattern = '.python...'
result = re.search(pattern,string)

pattern1 = '^abd'
pattern2 = '^abc'
pattern3='py$'
pattern4='ay$'
result1 = re.search(pattern1,string)
result2 = re.search(pattern2,string)
result3 = re.search(pattern3,string)
result4 = re.search(pattern4,string)
print(result1)
print(result2)
print(result3)
print(result4)

string = 'abcdddfphp345pythony_py'
pattern1='py.*n'
pattern2='cd{2}'
pattern3='cd{3}'
pattern4='cd{2,}'
result1 = re.search(pattern1,string)
result2 = re.search(pattern2,string)
result3 = re.search(pattern3,string)
result4 = re.search(pattern4,string)
print(result1)
print(result2)
print(result3)
print(result4)

#模式选择符，会返回从左到右第一个被匹配的字段，与其在pattern中的先后位置无关
pattern='php|abc'
result=re.search(pattern,string)
print(result)

#模式单位符
string = 'abcdcdcdcdcdfphp345pythony_py'
pattern1='(cd){1,}'
pattern2='(cd)+'
pattern3='cd{1,}'
result1 = re.search(pattern1,string)
result2 = re.search(pattern2,string)
result3 = re.search(pattern3,string)
print(result1)
print(result2)
print(result3)
